package com.file.inpu.stream;

import java.io.*;

/**
 * Created by z on 2016/11/17.
 */
public class FileInputSteamDemo {

    /**
     * 读取文件指定文件大小
     * @param size
     */
    public void read(int size) {
         FileInputStream fileInputStream = null;
        try {
            long statTime = System.currentTimeMillis();
            File file = new File("text1"+size);
            if (file.exists()) {
                fileInputStream = new FileInputStream(file);
                byte[] readBuffer = new byte[1024];
                int readSize = 0;
                while ((readSize = fileInputStream.read(readBuffer)) >0) {
                    System.out.println(new String(readBuffer,0,readSize));
                }
            }

            long endTime = System.currentTimeMillis();
            System.out.println(size+"------------end ------------" + (endTime - statTime));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    public static void main(String args[]) {
        FileInputSteamDemo fisd = new FileInputSteamDemo();
        fisd.read(10240);
        fisd.read(102400);
        fisd.read(1024000);
    }

}
